<div class="mb-4">
    <div class="kv-editor-container">
        <div class="kv-grid" id="kvGrid">
            <!-- 键值对行将在这里动态生成 -->
        </div>

        <div class="mt-2 ms-5">
            <button type="button" class="btn btn-sm btn-outline-primary btn-small" id="addAttribute">
                <i class="bi bi-plus-lg"></i> 历史属性值
            </button>
            <button type="button" class="btn btn-sm btn-outline-success btn-small" id="customizeAttribute">
                <i class="bi bi-plus-lg"></i> 自添属性值
            </button>
            <button type="button" class="btn btn-sm btn-outline-info btn-small ms-2" id="showExample">
                <i class="bi bi-image"></i> 查看示例
            </button>
        </div>

    </div>

    <input type="hidden" name="details_json" id="detailsJson">
</div>

<datalist id="attributeKeys">
    <!-- 由JS动态生成 -->
</datalist>

<!-- 使用示例模态框 -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-modal="true" style="z-index: 1060;">
    <div class="modal-dialog modal-lg"> <!-- 使用大尺寸模态框确保图片清晰可见 -->
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">商品属性格式示例</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body text-center">
                <!-- 图片展示区域 -->
                <img src="/static/image/使用示例.png" alt="商品属性格式示例" class="img-fluid mb-3">
                <div class="alert alert-info text-start">
                    <strong>格式要求：</strong>
                    <ul class="mb-0">
                        <li>使用标准JSON数组格式 <code>[{...}, {...}]</code></li>
                        <li>每个对象包含单个键值对（如 <code>{"颜色":"红色"}</code>）</li>
                        <li>属性名不能重复</li>
                        <li>确保使用英文双引号</li>
                    </ul>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>


<style>
    .btn-small {
      padding: 0.25rem 0.5rem;
      font-size: 0.875rem;
    }


    /* 自定义样式 */
    #attributeTable td {
        vertical-align: middle;
    }

    .remove-row {
        line-height: 1;
        padding: 0.25rem 0.5rem;
    }

    .kv-editor-container {
        max-width: 800px;
        margin: 10px auto;
        padding: 5px;
        border: 1px solid #e0e0e0;
        border-radius: 8px;
        background-color: #f9f9f9;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    }

    .kv-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 15px;
        padding-bottom: 10px;
        border-bottom: 1px solid #eee;
    }

    .kv-grid {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .kv-row {
      display: flex;
      flex-wrap: nowrap;
      align-items: center;
      gap: 8px; /* 控制元素间距 */
    }

    .kv-row > div {
      flex-shrink: 0;
    }

    .kv-row:hover {
        border-color: #4d90fe;
        box-shadow: 0 1px 3px rgba(77, 144, 254, 0.1);
    }

    .kv-controls {
        display: flex;
        gap: 5px;
    }

    .kv-btn {
        width: 20px;
        height: 20px;
        border-radius: 50%;
        border: none;
        font-size: 18px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s;
    }

    .add-btn {
        background-color: #4CAF50;
        color: white;
    }

    .add-btn:hover {
        background-color: #388E3C;
    }

    .remove-btn {
        background-color: #f44336;
        color: white;
    }

    .remove-btn:hover {
        background-color: #d32f2f;
    }

    .kv-key, .kv-value {
        flex: 1;
    }

    .kv-key input, .kv-value input {
        width: 100%;
        padding: 8px 8px;
        border: 1px solid #ddd;
        border-radius: 4px;
        font-size: 14px;
        transition: border-color 0.2s;
    }

    .kv-key input:focus, .kv-value input:focus {
        border-color: #4d90fe;
        outline: none;
        box-shadow: 0 0 0 2px rgba(77, 144, 254, 0.2);
    }

    .duplicate {
        border-color: #f44336 !important;
        background-color: #ffebee;
    }

    .status-bar {
        margin-top: 15px;
        padding-top: 10px;
        border-top: 1px solid #eee;
        font-size: 14px;
        color: #757575;
        display: flex;
        justify-content: space-between;
    }

    .auto-save-notice {
        color: #4CAF50;
        font-weight: 500;
    }

    .storage-info {
        display: flex;
        gap: 15px;
    }

    .storage-btn {
        padding: 5px 10px;
        background: #e0e0e0;
        border: none;
        border-radius: 4px;
        cursor: pointer;
        font-size: 12px;
    }

    .storage-btn:hover {
        background: #d5d5d5;
    }


    .btn-small { /* 使用 class 替代 ID */
        font-size: 0.8rem;
        padding: 0.15rem 0.3rem;
    }

</style>
